<template>
    <div v-if="visible" class="global-loading-mask">
        <div class="loading-content">
            <dv-loading :size="200" />
            <div class="loading-text">加载中...</div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, nextTick } from 'vue'
let timer: ReturnType<typeof setTimeout> | null = null
const visible = ref(false)
function show() {
    visible.value = true
    if (timer) clearTimeout(timer)
    timer = setTimeout(() => {
        visible.value = false
    }, 5000)
}
function hide() {
    visible.value = false
    if (timer) clearTimeout(timer)
}
// 组件暴露方法
import { defineExpose } from 'vue'
defineExpose({ show, hide })
</script>

<style scoped>
.global-loading-mask {
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.loading-text {
    /* font-size: 14px; */
    font-size: 5px;
    font-weight: bold;
    background: linear-gradient(to right, #3be6fd 0%, #409eff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    /* 从左到右动态渐变 */
    animation: gradient 3s linear infinite;
    background-size: 200% 100%;
    background-position: 100% 0;
}

@keyframes gradient {
    0% {
        background-position: 100% 0;
    }

    100% {
        background-position: -100% 0;
    }

}
</style>